package stackexchange;

import java.lang.reflect.Method;
import java.util.Vector;

public class UserGroup {

	private Vector<User> users = new Vector<User>();

	public UserGroup(Vector<User> users) {
		this.users = users;
	}

	public UserGroup excludeUsers(Vector<User> excludedUsers) {
		Vector<User> newUsers = (Vector<User>) users.clone();
		for (int i = 0; i < excludedUsers.size(); i++) {
			// TODO to create new UserGroup without excludeds
		}
		return null;
	}

	public User getUser(int id) {
		for (int i = 0; i < users.size(); i++) {
			if (id == users.get(i).getId()) {
				return users.get(i);
			}
		}
		return null;
	}

	public Vector<User> getUsers() {
		return users;
	}

	public void showUsers(int limit) {
		System.out.println("-------------");
		for (int i = 0; i < limit; i++) {
			System.out.println(users.get(i));
		}
		System.out.println("-------------");
	}

	public void showUsers() {
		System.out.println("-------------");
		for (int i = 0; i < users.size(); i++) {
			System.out.println(users.get(i));
		}
		System.out.println("-------------");
	}

	public User getMinimumExpert(Vector<User> allUsers) {
		User user = allUsers.get(0);
		double minLevel = user.getExpertiseScore();
		for (int i = 1; i < allUsers.size(); i++) {
			if (allUsers.get(i).getExpertiseScore() > minLevel) {
				user = allUsers.get(i);
				minLevel = allUsers.get(i).getExpertiseScore();
			}
		}
		return user;
	}

	/**
	 * 
	 * @return sorted from highest to lowest
	 */
	public UserGroup sortOnExpertiseScore() {
		Vector<User> sortedUsers = new Vector<User>();
		Vector<User> allUsers = (Vector<User>) this.users.clone();

		while (allUsers.size() > 1) {
			User minUser = getMinimumExpert(allUsers);
			allUsers.remove(minUser);
			sortedUsers.add(minUser);
		}
		sortedUsers.add(allUsers.get(0));
		return new UserGroup(sortedUsers);
	}

}
